package com.atguigu.gmall2020.mock.db.buffer;

import java.util.ArrayList;
import java.util.List;

public  class  BufferQueue<T> {


    private List<T> outputList = new ArrayList<T>();
    private List<T> inputList = new ArrayList<T>();



    public void push(T value) {
        synchronized (inputList) {
            inputList.add(value);
        }
    }

    public void pushAll(List<T> list) {
        synchronized (inputList) {
            inputList.addAll(list);
        }
    }

    public int getInputListSize() {
        synchronized (inputList) {
            return inputList.size();
        }
    }

    public List<T> getOutputList() {
        return outputList;
    }

    public void swap() {
        synchronized(inputList) {
            List<T> temp = outputList;
            outputList = inputList;
            inputList = temp;

            inputList.clear();
        }
    }

}
